﻿using System.Collections.Generic;
using System.Linq;
using FreshCommonUtility.Dapper;
using FreshCommonUtility.SqlHelper;
using WeChatModel.DatabaseModel;

namespace WeChatDataAccess
{
    public class DailyverifylistData : BaseData<long, DailyverifylistModel>
    {
        /// <summary>
        /// 保存信息
        /// </summary>
        /// <param name="saveModel"></param>
        public long SaveModel(DailyverifylistModel saveModel)
        {
            if (saveModel == null) return 0;
            using (var conn = SqlConnectionHelper.GetOpenConnection())
            {
                if (saveModel.Id < 1)
                {
                    //新增
                    return conn.Insert<long, DailyverifylistModel>(saveModel);
                }

                //修改
                conn.Update(saveModel);
                return saveModel.Id;
            }
        }

        /// <summary>
        /// 根据审核用户记录
        /// </summary>
        /// <returns>查询日志记录</returns>
        public List<DailyverifylistModel> GetDailyVerifyList()
        {
            List<DailyverifylistModel> dataList;
            using (var conn = SqlConnectionHelper.GetOpenConnection())
            {
                dataList = conn.GetList<DailyverifylistModel>(new
                { IsDel = 0 })
                    ?.OrderBy(f => f.Id).ToList();
            }
            return dataList;
        }

        /// <summary>
        /// 根据审核用户记录
        /// </summary>
        /// <param name="verifyId">审核人用户id</param>
        /// <returns>查询日志记录</returns>
        public DailyverifylistModel GetDailyVerifyModelByVerifyId(long verifyId)
        {
            DailyverifylistModel data;
            using (var conn = SqlConnectionHelper.GetOpenConnection())
            {
                data = conn.GetList<DailyverifylistModel>(new
                { IsDel = 0, VerifyId = verifyId }).SingleOrDefault();
            }
            return data;
        }
    }
}
